<?php

namespace App\Models\Refund;

use App\Http\Controllers\Machine\RefundSignController;
use App\Models\RbhBaseModel;

class RefundSignModel extends RbhBaseModel
{
    protected $table = 'refund_sign';
    protected $guarded = [];

    /**
     * 获取模型
     * @param $request
     * @return mixed
     */
    public static function getModel($request) {
        $Model = self::where('goods_num', '>', 0);
        if ($request->input('keyword') || $request->input('sname')) {
            $supplyCollection = RefundSignController::getSupplyDataCache();
            $sName = $request->input('keyword') ?: $request->input('sname');
            $sids = $supplyCollection->filter(function ($item) use ($sName) {
                return str_contains($item->CName, $sName);
            })->pluck('ID')->toArray();
            $Model = $Model->whereIn('sid', $sids);
        }
        if ($request->input('sid'))
            $Model = $Model->where('sid', $request->input('sid'));
        if ($request->input('goods_name'))
            $Model = $Model->where('goods_name', 'like', $request->input('goods_name').'%');
        return $Model;
    }
}
